# -*- coding: utf-8 -*-

import psutil
import datetime
import time
from flask import Flask, jsonify
from flask_cors import cross_origin
app = Flask(__name__)

def get_process_info(process_name):
    process_info = {}
    for proc in psutil.process_iter(['pid', 'name', 'create_time']):
        if process_name in proc.info['name']:
            process_info['pid'] = proc.info['pid']
            process_info['name'] = proc.info['name']
            process_info['start_time'] = datetime.datetime.fromtimestamp(proc.info['create_time']).strftime('%Y-%m-%d %H:%M:%S')
            return process_info
    return None

@app.route('/get_process_info')
@cross_origin()  # 允许跨域访问这个路由
def get_process_info_route():
    process_info = get_process_info("XMind.exe")
    if process_info:
        return jsonify(process_info)
    else:
        return jsonify({'error': 'Process not found'})

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)




